<?php 
$username = $_POST['username'];
$password = $_POST['password'];

include("opendb.php");
include("functions.php");
$res = isValidUser($username,$password);
if($res!=1) {
echo "$username = $password";
exit;
}

$listingid = $_POST['listingid'];
$query = "select * from Users where Username='".$username."'";
$result = mysql_query($query) or die ("SQL Error".mysql_error());
$row=mysql_fetch_assoc($result);
$userid = $row['ID'];



		$lquery = "select * from PROPERTIES p inner join Prop_Owner_Con c on p.OID = c.Prop_OID where p.OID='".$listingid."' and c.Owner = '".$userid."'";
		$lresult = mysql_query($lquery) or die ("SQL Error".mysql_error());
		$listing_row=mysql_fetch_assoc($lresult);
		if (mysql_num_rows($lresult) === 0)
		{
			echo "101";
			exit;
		}


if(isset($_POST['listingid']))
{
	$sql = "insert into Events (Title, Event_Type, Event_Date, Time_From, Time_To, Time_Fix, Notes, Price, Owner, Listing_ID, Date_Created)".
	" Values ('".$_POST['title']."', '".$_POST['type']."', '".$_POST['date']."', '".$_POST['from']."', '".$_POST['to']."', '".$_POST['fix']."', '".$_POST['notes'].
	"', '', '".$userid."', '".$listingid."', '".date('Y-m-d H-i-s')."')";
	
	$result = mysql_query($sql) or die ("SQL Error".mysql_error());
}

	
echo "1";
?>